<template>
  <!-- 404 页面内容 -->
  <div class="not-found-page">
    <!-- 404 图标 -->
    <div class="illustration">
      <span class="icon" :style="iconStyle">404</span>
    </div>

    <!-- 提示信息 -->
    <div class="message">
      <h1 class="title">哎呀，页面不见啦！</h1>
      <p class="description">
        您访问的页面可能被外星人带走了，或者它从未存在过。<br />
        不用担心，试试下面的方法：
      </p>
    </div>

    <!-- 操作按钮 -->
    <div class="actions">
      <!-- 默认按钮 -->
      <router-link
          v-if="!customButtons"
          to="/"
          class="action-button"
          :class="color"
          @click="handleButtonClick('home')"
      >
        返回首页
      </router-link>
      <router-link
          v-if="!customButtons"
          to="/search"
          class="action-button"
          :class="color"
          @click="handleButtonClick('search')"
      >
        搜索相册
      </router-link>

      <!-- 自定义按钮 -->
      <button
          v-for="(button, index) in customButtons"
          :key="index"
          class="action-button"
          :class="color"
          @click="handleButtonClick(button.key)"
      >
        {{ button.text }}
      </button>
    </div>
  </div>
</template>

<script setup>
import {defineProps, defineEmits, computed} from "vue";

// 定义 props
const props = defineProps({
  customButtons: {
    type: Array,
    default: () => [], // 格式: [{ key: 'home', text: '返回首页' }, { key: 'search', text: '搜索相册' }]
  },
  color: {
    type: String,
    default: "blue", // 默认颜色
    validator: (value) =>
        [
          "blue",
          "red",
          "yellow",
          "green",
          "purple",
          "orange",
          "pink",
          "teal",
          "cyan",
          "indigo",
          "lime",
          "amber",
        ].includes(value), // 支持的颜色
  },
});

// 定义 emits
const emit = defineEmits(["button-click"]);

// 按钮点击事件
const handleButtonClick = (key) => {
  emit("button-click", key);
};

// 动态计算 404 文字的渐变色
const iconStyle = computed(() => {
  const gradient = gradientColors[props.color] || gradientColors.blue;
  return {
    background: `linear-gradient(135deg, ${gradient[0]}, ${gradient[1]})`,
    "-webkit-background-clip": "text",
    "-webkit-text-fill-color": "transparent",
  };
});

// 渐变色配置
const gradientColors = {
  blue: ["#2196F3", "#1976D2"], // 蓝色
  red: ["#FF5252", "#D32F2F"], // 红色
  yellow: ["#FFD740", "#FFC400"], // 黄色
  green: ["#4CAF50", "#388E3C"], // 绿色
  purple: ["#9C27B0", "#7B1FA2"], // 紫色
  orange: ["#FF9800", "#F57C00"], // 橙色
  pink: ["#E91E63", "#C2185B"], // 粉色
  teal: ["#009688", "#00796B"], // 青色
  cyan: ["#00BCD4", "#0097A7"], // 蓝绿色
  indigo: ["#3F51B5", "#303F9F"], // 靛蓝色
  lime: ["#CDDC39", "#AFB42B"], // 柠檬绿
  amber: ["#FFC107", "#FFA000"], // 琥珀色
};
</script>

<style scoped>
.not-found-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 65px);
  padding: 20px;
  text-align: center;
}

.illustration {
  font-size: 8rem;
  font-weight: bold;
  margin-bottom: 40px;
  animation: bounce 2s infinite;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-20px);
  }
}

.message {
  margin-bottom: 30px;
}

.title {
  font-size: 2.5rem;
  color: #333;
  margin-bottom: 10px;
}

.description {
  font-size: 1.1rem;
  color: #666;
  line-height: 1.6;
}

.actions {
  display: flex;
  gap: 20px;
}

.action-button {
  padding: 12px 24px;
  border: none;
  border-radius: 25px;
  color: white;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.3s ease;
}

/* 颜色样式 */
.action-button.blue {
  background: linear-gradient(135deg, #2196F3, #1976D2);
}

.action-button.red {
  background: linear-gradient(135deg, #FF5252, #D32F2F);
}

.action-button.yellow {
  background: linear-gradient(135deg, #FFD740, #FFC400);
}

.action-button.green {
  background: linear-gradient(135deg, #4CAF50, #388E3C);
}

.action-button.purple {
  background: linear-gradient(135deg, #9C27B0, #7B1FA2);
}

.action-button.orange {
  background: linear-gradient(135deg, #FF9800, #F57C00);
}

.action-button.pink {
  background: linear-gradient(135deg, #E91E63, #C2185B);
}

.action-button.teal {
  background: linear-gradient(135deg, #009688, #00796B);
}

.action-button.cyan {
  background: linear-gradient(135deg, #00BCD4, #0097A7);
}

.action-button.indigo {
  background: linear-gradient(135deg, #3F51B5, #303F9F);
}

.action-button.lime {
  background: linear-gradient(135deg, #CDDC39, #AFB42B);
}

.action-button.amber {
  background: linear-gradient(135deg, #FFC107, #FFA000);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .title {
    font-size: 2rem;
  }

  .description {
    font-size: 1rem;
  }

  .actions {
    flex-direction: column;
    gap: 10px;
  }

  .action-button {
    width: 100%;
    text-align: center;
  }
}
</style>